package com.zxw.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zxw.service.UserService;
import com.zxw.service.exception.ExceptionUtils;
import org.springframework.stereotype.Service;

/**
 * @author zxw
 * @date 2021-01-11 14:43
 */
@Service
public class UserServiceImpl implements UserService {
    static int a = 0;
    @Override
    @SentinelResource(value = "addUser",blockHandler = "handleException",blockHandlerClass = ExceptionUtils.class)
    public void addUser() {
        a++;
        System.out.println(a);
//        throw new RuntimeException("message");
    }

    // blockHandler 函数，原方法调用被限流/降级/系统保护的时候调用
    public String blockHandlerForGetUser(String id, BlockException ex) {
        return "admin";
    }
}
